package com.yx.front.converter;

import cn.hutool.core.date.DateUtil;
import com.yx.front.model.CommentsReply;
import com.yx.front.model.vo.CommentsReplyVo;
import com.yx.front.enums.TimeFormat;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author YangXiong
 */
@Component
public class CommentsReplyConverter {
    public static List<CommentsReplyVo> handlerResult(List<CommentsReply> records) {
        List<CommentsReplyVo> vos = new ArrayList<>();
        records.forEach(one->{
            CommentsReplyVo vo = new CommentsReplyVo();
            vo.setId(one.getId());
            vo.setContent(one.getContent());
            vo.setCommentId(one.getCommentId());
            vo.setFromAvatar(one.getFromAvatar());
            vo.setFromId(one.getFromId());
            vo.setFromName(one.getFromName());
            vo.setToId(one.getToId());
            vo.setToAvatar(one.getToAvatar());
            String format = DateUtil.format(one.getUpdateTime(), TimeFormat.TIME_FORMAT);
            vo.setUpdateTime(format);
            vo.setToName(one.getToName());
            vos.add(vo);
        });
        return vos;
    }
}
